<?php
class videoActions extends BaseAdminActions{
    public $video;
    public function __construct(){
        Files::factory('video');
        $this->video = new Video();
        parent::__construct();
    }
    public function actionsIndex()
    {
        $this->actionsList();
    }
    public function actionsList()
    {
        $rs = $this->video->getAllVideos();
        $matchs = $this->video->getAllMatchs(false);
        $stars = $this->video->getAllStars();
        $this->assign('rs', $rs);
        $this->assign('matchs', $matchs);
        $this->assign('stars', $stars);
        
        $this->display('list.tpl.php');
    }
    public function actionsSet()
    {
        $do = Http::get('do');
        if ($do){
            $res = '失败';
            if ($do=='del'){
                $sql ="DELETE FROM ".$this->video->table." WHERE id= '".Http::get('id')."' LIMIT 1 ";
                $this->video->db->delete($sql);
                die('删除成功');
            }
            $data = array(
                    'star'=>Http::post('star'),
                    'tostar'=>Http::post('tostar'),
                    'match'=>Http::post('match'),
                    'link'=>Http::post('link'),
                    'thumb'=>Http::post('thumb'),
                    'title'=>Http::post('title'),
                    'content'=>Http::post('content'),
                    'updateTime'=>date("Y-m-d H:i:s")
                    );
            if ($do=='add'){
                $data['createTime']=date("Y-m-d H:i:s");
                if($this->video->db->insert($this->video->table, $data)){
                    $res = '添加成功';
                }
            }
            if ($do=='update'){
                if($this->video->db->updateData($this->video->table, $data, " WHERE id = ".Http::get('id'))){
                    $res = '修改成功';
                }
            }
            
            die($res);
        }
        if (Http::get('id')){
            $row = $this->video->getOneVideo(Http::get('id'));
        }else {
            $row = false;
        }
        
        $this->assign('match', $this->video->getAllMatchs(false));
        $this->assign('row', $row);
    }
    
    
    public function actionsMatchs()
    {
        $rs = $this->video->getAllMatchs();
        $this->assign('rs', $rs);         
    }
    public function actionsMatchsSet()
    {
        $do = Http::get('do');
        if ($do){
            $res = '失败';
            if ($do=='del'){
                $sql ="DELETE FROM ".$this->video->t_matchs." WHERE id= '".Http::get('id')."' LIMIT 1 ";
                $this->video->db->delete($sql);
                die('删除成功');
            }
            $data = array(
                    'name'=>Http::post('name'),
                    'type'=>Http::post('type'),
                    'info'=>Http::post('info'),
                    'logo1'=>Http::post('logo1'),
                    'logo2'=>Http::post('logo2'),
                    'space'=>Http::post('space'),
                    'link'=>Http::post('link'),
                    'stime'=>Http::post('stime'),
                    'etime'=>Http::post('etime')
                    );
            if ($do=='add'){
                if($this->video->db->insert($this->video->t_matchs, $data)){
                    $res = '添加成功';
                }
            }
            if ($do=='update'){
                if($this->video->db->updateData($this->video->t_matchs, $data, " WHERE id = ".Http::get('id'))){
                    $res = '修改成功';
                }
            }
            
            die($res);
        }
        if (Http::get('id')){
            $row = $this->video->getOneMatchs(Http::get('id'));
        }else {
            $row = false;
        }
        $this->assign('row', $row);
    }
    
    
}